import { get } from '@/utils/http'
const app = getApp()
Component({
  properties: {
    roomSetType:Array,
    info: Object,
    roomSet: Array
  },
  data: {
    api: app.globalData.api,
    imgList:[],
    setType: []
  },
  methods: {
    handleDevType(arr:Array<string>) {
      let type = this.properties.roomSetType
      let arr2 = [] 
      const map = new Map()
      arr.forEach(el => {
        let xx = type.find(e => e.list.find(ele => el == ele.name))
        let list = [] as Array<string>
        if (map.has(xx.id))list = [...map.get(xx.id),el]
        else list.push(el)
        map.set(xx.id, list)
      })
      map.forEach((value,key) => {
        arr2.push({ name:key, list: value})
      })
      this.setData({ setType: arr2 })
    },
    goOrder() {
      this.triggerEvent('goOrder')
    }
  },
  lifetimes: {
    attached: function() {
      this.setData({
        imgList: this.properties.info.room_image.split(',')
      })
      this.handleDevType(this.properties.roomSet)
    },
    detached: function() {
      
    }
  },
})